function R=polcar(I)
[F C]=size(I);
I_new=zeros(F,C);
for x=1:C 
  for y=1:F 
      
      r=sqrt(x^2+y^2);
      if(r>=1 & r <=512)
          angle=atan2(y,x);
          if(angle<0)
            angle=angle+2*pi;
          end  
          I_new(x,y)=interpolate(I,r,angle,1,512,512,512,512,512);
      end   
  end
end
R=I_new;
end






















function v = interpolate (imP, r, t, rMin, rMax, M, N, delR, delT)
    ri = 1 + (r - rMin)/delR;
    ti = 1 + t/delT;
    rf = floor(ri);
    rc = ceil(ri);
    tf = floor(ti);
    tc = ceil(ti);
    if tc > N
        tc = tf;
    end
    if rf == rc & tc == tf
        v = imP (rc, tc);
    elseif rf == rc
        v = imP (rf, tf) + (ti - tf)*(imP (rf, tc) - imP (rf, tf));
    elseif tf == tc
        v = imP (rf, tf) + (ri - rf)*(imP (rc, tf) - imP (rf, tf));
    else
       A = [ rf tf rf*tf 1
             rf tc rf*tc 1
             rc tf rc*tf 1
             rc tc rc*tc 1 ];
       z = [ imP(rf, tf)
             imP(rf, tc)
             imP(rc, tf)
             imP(rc, tc) ];
       a = A\double(z);
       w = [ri ti ri*ti 1];
       v = w*a;
    end
end